package com.yidu.BusinessData.controller;

import com.yidu.BusinessData.entity.Broker;
import com.yidu.BusinessData.service.BrokerServce;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 券商设置的总控制器
 * @author zhouhongyu
 * @since 2022/8/10
 * @version 1.0
 */
@RestController
public class BrokerController {
     @Autowired
     private BrokerServce brokerServce;//自动装配

    /**
     * 条件查询加分页
     * @param brokerName 模糊查询
     * @param page 起始页
     * @param limit 页数
     * @return 查询方法
     */
     @RequestMapping("selectBroker")
     public Map selectBroker(String brokerName,int page,int limit){
        System.out.println("这是分页条件查询的控制器");
        if (brokerName==null){
            brokerName="";
        }
             List<Broker> brokerList = brokerServce.selectBroker("%"+brokerName+"%",page,limit);
         for (Broker b :
                 brokerList) {
             System.out.println(b);
         }
         int i = brokerServce.selectCount();
         Map map = new HashMap();
         map.put("code",0);
         map.put("msg","");
         map.put("count",i);
         map.put("data",brokerList);
         return map;
     }

    /**
     * 插入数据
     * @param broker 券商
     * @return 增加方法
     */
     @RequestMapping("/insertBroker")
     public String insertBroker(Broker broker){
         System.out.println("这是增加数据的控制器");
         int i = brokerServce.insertBroker(broker);
         if (i == 1){
             return "增加成功";
         }else{
             return "增加失败";
         }
     }

    /**
     * 删除数据
     * @param brokerId 券商编号
     * @return 删除方法
     */
     @RequestMapping("/deleteBroker")
     public String deleteBroker(String brokerId){
         System.out.println("这是删除数据的控制器");
         System.out.println("brokerId = "+brokerId);
        int ad =  brokerServce.deleteBroker(brokerId);
        if (ad != 1){
            return "yes";
        }else{
            return "no";
        }
     }

    /**
     * 修改数据
     * @param broker
     * @return
     */
     @RequestMapping("/updateBroker")
     public String updateBroker(Broker broker){
         System.out.println("这是修改数据的控制器");
         int i = brokerServce.updateBroker(broker);
         if (i == 1){
             return "修改成功";
         }else{
             return "修改失败";
         }
     }

}
